package org.broadway.monitor;

import org.broadway.interfaces.Action;
import org.broadway.interfaces.Context;
import org.broadway.interfaces.Evaluator;
import org.broadway.interfaces.ResourceCollector;

/**
 * AMonitor is an abstract implementation of the Monitor interface.
 * The monitor interface represents a component that can monitor a
 * set of given resources. 
 * Extends this class to inherit common functionalities of a monitor.
 * 
 * @author vladimir vivien
 * @see Monitor
 * @see Scanner
 *
 */
public abstract class AMonitor implements Monitor{
	private ResourceCollector resources;
	private Evaluator evaluator;
	private Action action;
	private Context context;

	/**
	 * Constructor
	 *
	 */
	public AMonitor() {
		context = new MonitorContext();
	}
	
	/**
	 * Setter for a Broadway context object.
	 */
	public void setContext(Context ctx) {
		this.context = ctx;
	}
	
	/**
	 * Getter object for context.
	 * @return
	 */
	public Context getContext() {
		if(context == null) {
			context = new MonitorContext();
		}
		return context;
	}
	
	/**
	 * Setter for the monitor's resource collector.
	 * @see ResourceCollector
	 */
	public void setResourceCollector (ResourceCollector resCollector) {
		this.resources = resCollector;
	}
	
	/**
	 * Getter for resource collector.
	 * @return
	 */
	public ResourceCollector getResourceCollector() {
		if(resources == null){
			resources = new MappedResourceCollector();
		}
		return resources;
	}
	
	/**
	 * Getter for the monitor's evaluator object.
	 * @return Evaluator
	 * @see Evaluator
	 */
	public Evaluator getEvaluator() {
		if(evaluator == null) {
			evaluator = new StringExpressionEvaluator();
		}
		return evaluator;
	}
	
	/**
	 * Setter for evaluator.
	 * @param eval
	 */
	public void setEvaluator(Evaluator eval) {
		this.evaluator = eval;
	}

	/**
	 * Setter for the Monitor's Action object. 
	 * @param action
	 */
	public void setAction(Action action) {
		this.action = action;
	}
	
	/**
	 * Getter for monitor's action.
	 * @return Action
	 */
	public Action getAction() {
		return this.action;
	}
	
}
